<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        for (var i = 0; i <= 10; i++) {   //var 是全局作用域，执行完才进行settimeout打印的都是11
            setTimeout(() => {
                console.log(i);
            }, 1000 * i)
        }

        for (let i = 0; i <= 10; i++) {   //let 由于是块级作用域
            setTimeout(() => {
                console.log(i);
            }, 1000 * i)
        }

        for (var i = 1; i <= 10; i++) {
            (function (i) {
                setTimeout(function () {
                    console.log(i);
                }, 1000 * i)
            })(i);
        }
    </script>
</body>

</html>